// `include "adder4.v"
module adder16(
    input  wire [15:0]  a   ,//输入数据，二进制补码
    input  wire [15:0]  b   ,//输入数据，二进制补码
    input  wire         cin ,//来自低位的进位输入
    output wire [15:0]  out ,//输出和a + b，二进制补码（不包含最高位的进位）
    output wire         cout //输出和a + b，的进位
);



wire [15:0] p = a|b;
wire [15:0] g = a&b;
wire [3:0] P, G;
wire [15:0] c;

assign c[0] = cin;

adder4 C0_3(.p(p[3:0]),.g(g[3:0]),.cin(c[0]),.P(P[0]),.G(G[0]),.cout(c[3:1]));
adder4 C4_7(.p(p[7:4]),.g(g[7:4]),.cin(c[4]),.P(P[1]),.G(G[1]),.cout(c[7:5]));
adder4 C8_11(.p(p[11:8]),.g(g[11:8]),.cin(c[8]),.P(P[2]),.G(G[2]),.cout(c[11:9]));
adder4 C12_15(.p(p[15:12]),.g(g[15:12]),.cin(c[12]),.P(P[3]),.G(G[3]),.cout(c[15:13]));
adder4 C_INTER(.p(P),.g(G),.cin(c[0]),.P(),.G(),.cout({c[12],c[8],c[4]}));

assign cout = (a[15]&b[15]) | (a[15]&c[15]) | (b[15]&c[15]);
assign out = (~a&~b&c)|(~a&b&~c)|(a&~b&~c)|(a&b&c);

endmodule